home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / GRAPHIC / REFLIST.H < prev    next >
C/C++ Source or Header  |  1991-12-10  |  3KB  |  118 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /* RefList class */
  24.  
  25. #ifndef reflist_h
  26. #define reflist_h
  27.  
  28. #include <InterViews/defs.h>
  29. #include <InterViews/Graphic/ref.h>
  30.  
  31. class RefList : public Ref {
  32. public:
  33.     RefList();
  34.     RefList(UID);
  35.     RefList(Persistent*);
  36.     ~RefList();
  37.  
  38.     void SetRef(Ref r);
  39.  
  40.     boolean IsEmpty();
  41.     void Append(RefList*);
  42.     void Prepend(RefList*);
  43.     void Remove(RefList*);
  44.     void Delete(Ref);
  45.     RefList* Find(Ref);
  46.     RefList* First();
  47.     RefList* Last();
  48.     RefList* End();
  49.     RefList* Next();
  50.     RefList* Prev();
  51.  
  52.     boolean Write(PFile*);
  53.     boolean Read(PFile*);
  54.     boolean WriteObjects(PFile*);
  55.     boolean ReadObjects(PFile*);
  56.  
  57.     RefList* operator[](int count);
  58. protected:
  59.     RefList* next;
  60.     RefList* prev;
  61. };
  62.  
  63. /*
  64.  * inlines
  65.  */
  66.  
  67. inline RefList::RefList () : () { next = this; prev = this; }
  68. inline RefList::RefList (UID u) : (u) { next = this; prev = this; }
  69. inline RefList::RefList (Persistent* p) : (p) { next = this; prev = this; }
  70.  
  71. inline RefList::~RefList () {
  72.     uid(INVALIDUID);
  73.     next = (RefList*) -2;
  74.     prev = (RefList*) -3;
  75. }
  76.  
  77. inline boolean RefList::IsEmpty () { return next == this; }
  78. inline void RefList::SetRef (Ref r) { uid(r.uid()); }
  79.  
  80. inline void RefList::Append (RefList* e) {
  81.     prev->next = e;
  82.     e->prev = prev;
  83.     e->next = this;
  84.     prev = e;
  85. }
  86.  
  87. inline void RefList::Prepend (RefList* e) {
  88.     next->prev = e;
  89.     e->prev = this;
  90.     e->next = next;
  91.     next = e;
  92. }
  93.  
  94. inline void RefList::Remove (RefList* e) {
  95.     e->prev->next = e->next;
  96.     e->next->prev = e->prev;
  97.     e->prev = (RefList*) -1;
  98.     e->next = (RefList*) -1;
  99. }
  100.  
  101. inline void RefList::Delete (Ref p) {
  102.     register RefList* e;
  103.  
  104.     e = Find(p);
  105.     if (e != nil) {
  106.     Remove(e);
  107.     delete e;
  108.     }
  109. }
  110.  
  111. inline RefList* RefList::First () { return next; }
  112. inline RefList* RefList::Last () { return prev; }
  113. inline RefList* RefList::End () { return this; }
  114. inline RefList* RefList::Next () { return next; }
  115. inline RefList* RefList::Prev () { return prev; }
  116.  
  117. #endif
  118.